#ifndef _MUTEX_H_
#define _MUTEX_H_

#include <util/win/osdef.h>

typedef CRITICAL_SECTION os_mutex_t;
typedef HANDLE os_sem_t;

typedef union {
    CONDITION_VARIABLE cond_var;
    struct {
        unsigned int waiters_count;
        CRITICAL_SECTION waiters_count_lock;
        HANDLE signal_event;
        HANDLE broadcast_event;
    } fallback;
}os_cond_t;

typedef union {
    struct {
        unsigned int num_readers_;
        CRITICAL_SECTION num_readers_lock_;
        HANDLE write_semaphore_;
    } state_;
    struct {
        SRWLOCK unused_;
    } unused1_;
    struct {
        os_mutex_t unused1_;
        os_mutex_t unused2_;
    } unused2_;
}os_rwlock_t;

typedef struct {
    unsigned int n;
    unsigned int count;
    os_mutex_t mutex;
    os_sem_t turnstile1;
    os_sem_t turnstile2;
}os_barrier_t;

typedef struct {
  DWORD tls_index;
} os_key_t;

typedef struct os_once_s {
  unsigned char ran;
  HANDLE event;
} os_once_t;

#define OS_ONCE_INIT { 0, NULL }

#endif